package com.hxd.mall.utils.local

import com.hexin.locallibrary.network.SignUtils
import okhttp3.RequestBody
import org.json.JSONObject
import java.util.*

/**
 * post-json格式验签 需要调用此方法生成body
 */
object RequestUtil {

    fun getRequestBody(map: TreeMap<String, Any>): RequestBody {
        val rootJsonObject = JSONObject()
        if (map.size > 0) {
            map.keys.forEach {
                rootJsonObject.put(it, map[it])
            }
        }
        rootJsonObject.put("appSignKey", SignUtils.AppSign(map))
        val strEntity = rootJsonObject.toString()
        return RequestBody.create(
            okhttp3.MediaType.parse("application/json;charset=UTF-8"),
            strEntity
        )
    }

}